package com.hucheng.seckill.vo;

import com.hucheng.seckill.entity.SeckillGoodsDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 返回参数
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SeckillGoodsVO implements Serializable {
    /**
     * 秒杀商品ID
     */
    private Integer seckillGoodsId;
    /**
     * 商品ID
     */
    private Integer goodsId;
    /**
     * 秒杀商品价格
     */
    private BigDecimal seckillPrice;
    /**
     * 库存数量
     */
    private Integer stockCount;
    /**
     * 秒杀商品开始时间
     */
    private String dateStart;
    /**
     * 秒杀商品结束时间
     */
    private String dateEnd;
    /**
     * 秒杀商品创建时间
     */
    private String seckillGoodsDateCreated;
    /**
     * 秒杀商品修改时间
     */
    private String seckillGoodsDateUpdated;
    /**
     * 1秒杀未开始 2秒杀中 3秒杀已结束
     */
    private Integer status;

    /**************商品信息***************/
    /**
     * 商品名称
     */
    private String goodsName;
    /**
     * 商品标题
     */
    private String goodsTitle;
    /**
     * 商品主图
     */
    private String goodsImg;
    /**
     * 商品描述
     */
    private String goodsDetail;
    /**
     * 商品价格
     */
    private String goodsPrice;
    /**
     * 商品库存
     */
    private String goodsStock;
    /**
     * 商品创建时间
     */
    private String goodsDateCreated;
    /**
     * 商品修改时间
     */
    private String goodsDateUpdated;

    public static SeckillGoodsVO buildSeckillGoodsVO(final SeckillGoodsDO seckillGoodsDO) {
        if (seckillGoodsDO == null) {
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return new SeckillGoodsVO(
                seckillGoodsDO.getSeckillGoodsId(),
                seckillGoodsDO.getGoodsId(),
                seckillGoodsDO.getSeckillPrice(),
                seckillGoodsDO.getStockCount(),
                sdf.format(seckillGoodsDO.getDateStart()),
                sdf.format(seckillGoodsDO.getDateEnd()),
                dateTimeFormatter.format(seckillGoodsDO.getSeckillGoodsDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(seckillGoodsDO.getSeckillGoodsDateUpdated().toLocalDateTime()),
                seckillGoodsDO.getStatus(),
                seckillGoodsDO.getGoodsName(),
                seckillGoodsDO.getGoodsTitle(),
                seckillGoodsDO.getGoodsImg(),
                seckillGoodsDO.getGoodsDetail(),
                seckillGoodsDO.getGoodsPrice(),
                seckillGoodsDO.getGoodsStock(),
                dateTimeFormatter.format(seckillGoodsDO.getGoodsDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(seckillGoodsDO.getGoodsDateUpdated().toLocalDateTime()));
    }

}
